<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form>
        <input type="file" name="file">
        <button type="button" id="submit">提交图片</button>
    </form>
    <div>
        <img id="img" src="" alt=""/>
    </div>
    <script src="/js/jquery-2.1.0.min.js"></script>
    <script>
        $(function () {
            let fd = new FormData();
            $('input[type="file"]').change(function () {
                let file = $(this)[0].files
                fd.append("file",file[0])
            })
            console.log(fd)
            $('#submit').click(function (){
                $.ajax({
                    url:'/upload',
                    type: "POST",
                    data: fd,
                    contentType: false,
                    processData: false,
                    success: (res) => {
                        $('#img').attr('src',`/${res}`)
                    }
                })
            })
        })
    </script>
</body>
</html>